<template>
	<view> 
		<view class="detail-box">
			<view class="cu-form-group">
				<view class="title">商品名称：<span class="padd_left">{{NowSelectGoods.GoodsName}}</span></view>
				<span style="float: right;color: rgb(140, 140, 140);">不可以修改</span>
				<!-- <button class="cu-btn round stop text-white" @tap="gogoodlist">查询</button> -->
			</view>
			<!-- <span class="padd_left"></span> -->
			<view class="cu-form-group"> 
				<view class="title">编　　号：<span class="padd_left">{{NowSelectGoods.GoodsCode}}</span></view>
				<span style="float: right;color: rgb(140, 140, 140);">不可以修改</span>
			</view>
			<view class="cu-form-group">
				<view class="title">规　　格：<span class="padd_left">{{NowSelectGoods.Spec}}</span></view>
				<span style="float: right;color: rgb(140, 140, 140);">不可以修改</span>
				<!-- <input class="inpt" name="input" disabled="true" v-model="NowSelectGoods.Spec"></input> -->
				<!-- <button class="cu-btn round stop text-white" @tap="showModal" data-target="Modal">查询</button> -->
			</view>
			<view class="cu-form-group" @click="clickopen(2,'仓库')">
				<view class="title">仓　　库：<span class="padd_left">{{NowSelectGoods.stockName}}</span></view>
				<!-- <span style="float: right;color: rgb(140, 140, 140);">不可以修改</span> -->
			</view>
			<view class="cu-form-group" v-if="Isdistribution == 1" @click="clickopen(5,'配入仓库')">
				<view class="title">配入仓库：<span class="padd_left">{{NowSelectGoods.stockName2}}</span></view>
				<!-- <span style="float: right;color: rgb(140, 140, 140);">不可以修改</span> -->
			</view>
			<view class="cu-form-group" @click="clickopen(4,'单位')">
				<view class="title">单　　位：</view>
				<input class="inpt" name="input" disabled="true" v-model="NowSelectGoods.UnitName"></input>
				<!-- <span style="float: right;color: rgb(140, 140, 140);">不可以修改</span> -->
				<!-- <button class="cu-btn round stop text-white" @tap="showModal" data-target="Modal">查询</button> -->
			</view>
			<view class="cu-form-group" @click="clickopen(3,'赠品')">
				<view class="title">赠　　品：<span class="padd_left">{{Gname}}</span></view>
				<!-- <span style="float: right;color: rgb(140, 140, 140);">不可以修改</span> -->
			</view>
			<!-- <view class="cu-form-group" >
			<view class="title">批　　号：<span v-if="IsBatch == true" class="padd_left">{{NowSelectGoods.BatchNo}}</span>
			
			</view>
			<input v-if="IsBatch != true" disabled="true"  placeholder="不可选择批号"></input> 
			<button class="cu-btn  stop text-white" style="background-color: #518abc;" v-show="IsBatch == true" @tap="XHGetBatchNoFollow()">选择批号</button>
			</view> -->
			
			<view class="cu-form-group" >
				<view class="title">批　　号：
				</view>
				<input :disabled="!IsBatch" v-model="NowSelectGoods.BatchNo" @input="GetBatchNo" :placeholder="IsBatch==true?'请输入批号或者选择批号':'不是批号商品'"></input>
				<button class="cu-btn  stop text-white" style="background-color: #518abc;" v-if="IsBatch==true"  @tap.stop="XHGetBatchNoFollow()">选择批号</button>
			</view>
			
			<!-- IsBatch -->
			<view class="cu-form-group"  @tap="changeShow('QS_Picekr_date',0)" data-url="111223">
				<view class="title">生产日期：</view>
					<input disabled="true" :value="ProductionDate" :placeholder="datePlaceHolder"></input>
			</view>
			<view class="cu-form-group" @tap="changeShow('QS_Picekr_date',1)">
				<view class="title">有效日期：</view>
					<input disabled="true" :value="validityDate" :placeholder="datePlaceHolder"></input>
			</view>
			<view class="cu-form-group">
				<view class="title">税　　率：</view>
				<input class="inpt" type="number" name="input" placeholder="点击修改" v-model="NowSelectGoods.Tax" ></input>
			</view>
			<view class="cu-form-group" >
				<view class="title">单　　价：</view>
				<input type="number" v-model="NowSelectGoods.Price" placeholder="请输入单价">
				<button class="cu-btn  stop text-white" style="background-color: #518abc;" @click="clickopen(1,'单价')" >选择单价</button>
				
				<!-- <button class="cu-btn round stop text-white">查询</button> -->
			</view>
			<view class="cu-form-group">
				<view class="title">折　　扣：</view>
				<input class="inpt" type="number" name="input" placeholder="点击修改" v-model="NowSelectGoods.Discount" ></input>
			</view>
		<!-- 	<view class="cu-form-group">
				<view class="title">批号：</view>
				<input class="inpt" name="input" disabled="true" ></input> -->
				<!-- <button class="cu-btn round stop text-white" @tap="showModal" data-target="Modal">查询</button> -->
		<!-- 	</view> -->
			
			<view class="cu-form-group">
				<view class="title">数　　量：</view>
				<input class="inpt" type="number" name="input" placeholder="点击修改" v-model="NowSelectGoods.Qty" ></input>
			</view>

			<view class="cu-form-group">
				<view class="title">库　　存：</view>
				<input class="inpt" name="input" disabled="true" :value="NowSelectGoods.stockqty"></input>
			</view>
			<view class="cu-form-group">
				<view class="title">备　　注：</view>
				<input class="inpt" name="input" placeholder="点击修改" v-model="NowSelectGoods.Remark" ></input>
			</view>
			<view class="cu-form-group">
				<!-- <button class="cu-btn  stop text-white" @click="AddBillOrder">提交修改</button> -->
				<input class="inpt" name="input" disabled="true"></input>
				<button style="background-color: #518abc;" class="cu-btn  stop text-white" @click="addSelectGoods">提交修改</button>
			</view>
		</view>
		<view class="cu-modal " :class="isShowScanModel?'show':''">
			<view class="cu-dialog ls-main">
				<view class="cu-bar bg-ls justify-between">
					<view class="action">
						<view class="cuIcon-info text-white" v-show="false"></view>
					</view>
					<view class="content">选择批号</view>
					<view class="action" @tap="hideModal">
						<text class="cuIcon-close text-red"></text>
					</view>
				</view>
				<view class="padding text-left bg-white ls-contain">
					<scroll-view scroll-y style="height: 400px;padding-bottom: 100px">
						<view class="ls-box" @tap="choosesGoods(index)" v-for="(item,index) in storeList" :key='index' :data-index="index">
							<!-- <view class="text-black">数据库：</view> -->
							<view>批次号:{{item.FBatchNo}}</view>
						</view>
					</scroll-view>
				</view>
			</view>
			</view>
		<!-- <uni-calendar ref="calendar1" :insert="false" @confirm="confirm1" />
		<uni-calendar ref="calendar2" :insert="false" @confirm="confirm2" /> -->
		<!-- 时间选择器 -->
		<QSpicker title="请选择日期时间" mode="bottom" type="date" ref="QS_Picekr_date" pickerId="date_1" :dataSet="dateSet"
		 showReset :autoHide="false" contentColor="#33cc33" :lineHeight=".05" @hideQSPicker="hideQSPicker($event)"
		 @showQSPicker="showQSPicker($event)" @confirm="newconfirm($event)" />
		<!-- 弹出框HOME -->
		<view class="cu-modal cu_none " :class="modalName=='Modal'?'show':''">
			<view class="cu-dialog" :class="[{'new-cu-dialog':listshow == 3}]" >
				<view class="cu-bar bg-white justify-end">
					<view class="content">选择{{listcode}}</view>
					<view class="action" @tap="hideModal">
						<text class="cuIcon-close text-red"></text>
					</view>
				</view>
				<view style="padding: 5px 21px;">
				<view class="search" v-show="listshow == 11"><input class="inpt" placeholder="查询供应商" name="input"></input>
				<span class="search_span" @click="selectClient()">搜索</span>
				</view>
				<view class="search" v-show="listshow == 2"><input class="inpt"  placeholder="查询仓库" name="input"></input>
				<span class="search_span"  @click="selectwarehouse()">搜索</span>
				</view>
				<view class="search" v-show="listshow == 44"><input class="inpt"  placeholder="查询业务员" name="input"></input>
				<span class="search_span" @click="selectsalesmant()">搜索</span>
				</view>
				</view>
				<scroll-view style="height: 77%;" scroll-y="true">
					<view class="padding-xl" v-show="listshow == 1">
						<view>
							<view class="btn_list"  v-for="(item,index) in Pricelist" 
							 @click="clickPrice(index)" :key="item.id">{{item.ShowValue}}</view>			
						</view>
					</view>
				<view class="padding-xl" v-show="listshow == 2">
					
					<view>
						<view class="btn_list"  v-for="(item,index) in StoreLists" 
						 @click="checkware(index)" :key="item.id">{{item.StoreName}}</view>			
					</view>
				</view>
				<view class="padding-xl" v-show="listshow == 3">
					<view>
						<view class="btn_list"  v-for="(item,index) in Gift" 
						 @click="clickGift(index)" :key="item.id">{{item.Gname}}</view>			
					</view>
				</view>
				<view class="padding-xl" v-show="listshow == 4">
					<view>
						<view class="btn_list"  v-for="(item,index) in GoodsUnit" 
						 @click="clickUnit(index)" :key="item.id">{{item.UnitName}}</view>			
					</view>
				</view>
				<view class="padding-xl" v-show="listshow == 5">
					<view>
						<view class="btn_list"  v-for="(item,index) in StoreLists2" 
						 @click="checkware2(index)" :key="item.id">{{item.StoreName}}</view>			
					</view>
				</view>
			
				</scroll-view>
			</view>
		</view>
		<!-- 弹出框END -->
	
	</view>
</template>
<script>
	import * as Api from '@/syApis/syAddOrder/syaddApis.js';
	// import uniCalendar from '@/components/uni-calendar/uni-calendar.vue';
	import QSpicker from '@/components/QuShe-picker/QuShe-picker.vue';
	import * as GetApi from '@/syApis/syHttp/Http.js';
	export default {
		data() {
			return {
				//选择的商品
				NowSelectGoods: {
					Price:0
				},
				//添加的备注
				GoodsRemark: "",
				//商品库存
				GoodsStorm: 0,
				//商品税率
				Tax: 0, 
				//商品
				GoodsQty: 0,
				//商品折扣
				GoodsDiscount: "",
				//仓库ID
				StoreID: "",
				//当前商品在原商品数组对应的位置
				SelectStockNum:"",
				storeList:[],
				StoreLists:[],
				StoreLists2:[],
				//生产日期
				ProductionDate:"",
				//有效日期
				validityDate:"",
				
				Inventorybatch:"",
				isShowScanModel:false,
				//日期palceholde
				datePlaceHolder:"点击选择日期",
				Gift:[{Gname:'否',Gid:0},{Gname:'是',Gid:1}],//是否赠品
				listshow:-1,
				modalName:null,
				Pricelist:[],//单价
				listcode:'',
				IsBatch:false,
				Gindex:0,
				Gname:'',
				GoodsUnit:[],//多单位
				//日期选择
				dateSet: {
					dateMode: 3,
					dateFormatArray: ['-', '-', ' ', ':', ':']
				},
				Isdistribution:null,//是否配入仓库
			}
		}, 
		components: {
			// uniCalendar,
			QSpicker
		},
		created() {
			this.GetStoreMessage();
		},
		onLoad(options) {
			// console.log(options);
			// console.log(options.goodData)
			this.NowSelectGoods = JSON.parse(options.goodData);
			this.source = JSON.parse(options.source);
			console.log('onload执行了')
			console.log(this.NowSelectGoods)
			this.StoreID = options.StoreID;
			this.index = options.selectIndex;
			this.IsBatch = this.NowSelectGoods.IsBatch;
			this.Inventorybatch = options.Inventorybatch;
			this.Isdistribution = options.Isdistribution;
			this.Bname = options.Bname;
			this.batch = options.batch;
			// orderType
			// validityDate
			// ProductionDate
			this.ProductionDate = this.timesubstr(this.NowSelectGoods.ProductionDate)
			this.validityDate = this.timesubstr(this.NowSelectGoods.validityDate)
		
			if(this.NowSelectGoods.IsGift == 0){
				this.Gname= '否'
			}else if(this.NowSelectGoods.IsGift == 1){
				this.Gname = '是'
			}else{
				this.Gname = '否'
			}
			
			if(this.IsBatch ==true){
				this.datePlaceHolder = "点击选择日期"
			}else{
				this.datePlaceHolder = "不可选择日期"
			}
			this.prices()
			this.getGoodsUnitMessage()
			console.log('初始化成功')
			console.log(this.NowSelectGoods)
			// this.SelectStockNum(this.NowSelectGoods.GoodsID);
		},
		
		methods: {
			//获取批号
			XHGetBatchNoFollow(){
				let data = {
					StoreID:this.NowSelectGoods.StoreID,
					GoodsID:this.NowSelectGoods.GoodsID,
					BillName:this.Bname,
				};
				var that = this;
				Api.XHGetBatchNoFollow(data,function(res){
					if(res.state){
						if(res.data.ErrorMsg=='获取登录信息失败'){
							
						}else if(res.data.ErrorMsg!=''){
							
						}else{
							var storeLists = []
							// that.storeList = that.timesubstr(that.storeList["FDate"])FValidDate
							for(var i in res.data.ResultMsg){
								if(res.data.ResultMsg[i]["FBatchNo"]!=""){
									storeLists.push(res.data.ResultMsg[i])
								}
							}
							// console.log(storeLists)
							if(storeLists.length>0){
								that.isShowScanModel = true;
								that.storeList = storeLists
							}else{
								Api.showTip('查无批号');
							}
						}
					}
				})
			},
			// choosesGoods(index){
			// 	this.validityDate.fulldate = this.storeList[index].FDate;
			// 	this.validityDate.fulldate = this.storeList[index].FValidDate;
			// 	this.NowSelectGoods.FDate = this.storeList[index].FDate;
			// 	this.NowSelectGoods.FValidDate =  this.storeList[index].FValidDate;
			// },
			choosesGoods(index){
				this.ProductionDate = this.timesubstr(this.storeList[index].FDate);
				this.validityDate = this.timesubstr(this.storeList[index].FValidDate);
				this.NowSelectGoods.ProductionDate = this.storeList[index].FDate;
				this.NowSelectGoods.validityDate =  this.storeList[index].FValidDate;
				this.NowSelectGoods.BatchNo =  this.storeList[index].FBatchNo;
				this.NowSelectGoods.stockqty = parseFloat(this.storeList[index].FQty);
				this.isShowScanModel = false;
			},
			//选中的赠品
			clickGift(evt){
				this.Gname = this.Gift[evt].Gname
				this.Gindex = this.Gift[evt].Gid
				this.modalName = null;
				console.log(this.Gindex)
			},
			// 选择单价
			clickPrice:function(evt){
				this.NowSelectGoods.Price = parseFloat(this.Pricelist[evt]["Price"])
				this.modalName = null;
			},
			//显示
			clickopen:function(evt,msg){
				this.listshow = Number(evt);
				this.listcode = msg;
				this.modalName = 'Modal';
			},
			//关闭
			hideModal(e) {
				//console.log(222)
				this.modalName = null;
				this.isShowScanModel =null
			},
			checkware:function(e){
				this.NowSelectGoods["StoreID"] = this.StoreLists[e]["StoreID"]
				this.NowSelectGoods["stockName"] = this.StoreLists[e]["StoreName"]
				this.GetStoreNum()
				this.modalName = null
			},
			checkware2:function(e){
				this.NowSelectGoods["StoreID2"] = this.StoreLists2[e]["StoreID"]
				this.NowSelectGoods["stockName2"] = this.StoreLists2[e]["StoreName"]
				// this.GetStoreNum()
				this.modalName = null
			},
			//选中的单位
			clickUnit:function(index){
				this.NowSelectGoods.UnitName = this.GoodsUnit[index]["UnitName"]
				this.NowSelectGoods.UnitID = this.GoodsUnit[index]["UnitID"]
				this.NowSelectGoods.urate = this.GoodsUnit[index]["urate"]
				this.modalName = null
				this.prices(1)
			},
			showQSPicker(res) {
				console.log(res);
			},
			hideQSPicker(res) {
			 
			},
			//显示选择日期界面
			changeShow(name, type) {
				this.startAndEndTime = type;
				this.$refs[name].show();
				this.dateName = name;
			},
			newconfirm(res) {
				// if (this.startAndEndTime == 0) {
				// 	this.startTime = res.data;
				// } else {
				// 	this.endTime = res.data;
				// }
				if(this.IsBatch==true){
					var data = GetApi.splitdate(res.data);//处理的日期
					if(this.startAndEndTime == 0){
						this.ProductionDate = data;
						this.NowSelectGoods.ProductionDate = data;
						this.validityDate = this.DateToTime(data,0,this.NowSelectGoods.Days);
						this.NowSelectGoods.validityDate = this.DateToTime(data,0,this.NowSelectGoods.Days);
					}else if(this.startAndEndTime == 1){
						this.validityDate = data;
						this.NowSelectGoods.validityDate = data;
						this.ProductionDate = this.DateToTime(data,1,this.NowSelectGoods.Days);
						this.NowSelectGoods.ProductionDate = this.DateToTime(data,1,this.NowSelectGoods.Days);
					}
					this.$refs[this.dateName].hide();
				}
				// console.log('点击了确认')
				// console.log(res)
				// console.log(this.startAndEndTime)
				
				// console.log("处理的日期")
				// console.log(data)
				// // var fulldata = res.data
				// // this.checkdata.BillTime = data
				// console.log(res)
				
			},
			// open1() {
			// 	if(this.IsBatch==true){
			// 		this.$refs.calendar1.open();
			// 	}
			// },
			// open2() {
			// 	if(this.IsBatch==true){
			// 		this.$refs.calendar2.open();
			// 	}
			// },
			// confirm1(e) {
			// 	// var fulldate = e.detail.fulldate
			// 	// console.log(e.detail.fulldate);
			// 	console.log(e)
			// 	this.ProductionDate = e.fulldate;
			// 	this.NowSelectGoods.ProductionDate = e.fulldate;
			// },
			// confirm2(e) {
			// 	// var fulldate = e.detail.fulldate
			// 	// console.log(e.detail.fulldate);
			// 	console.log(e)
			// 	this.validityDate = e.fulldate,
			// 	this.NowSelectGoods.validityDate = e.fulldate;
			// },
			//获取仓库
			GetStoreMessage() {
				let data = {
					Filter: ""
				}
				var that = this;
				Api.GetStoreMessage(data, function(res) {
					if (res.state) {
						if (res.data.ErrorMsg == "获取登录信息失败") {
							Api.showTip("登录超时");
						} else if (res.data.ErrorMsg != "") {
							Api.showTip(res.data.ErrorMsg);
						} else {
							// let responseData = res.data.ResultMsg;
							// NowSelectGoods.stockName
							that.StoreLists = res.data.ResultMsg;
							that.StoreLists2 = res.data.ResultMsg;
							// console.log('仓库获取成功')
							// console.log(that.StoreLists)
							// console.log(that.NowSelectGoods.StoreID)
							for(var i in that.StoreLists){
								if(that.StoreLists[i].StoreID == that.NowSelectGoods.StoreID){
									that.NowSelectGoods.stockName = that.StoreLists[i].StoreName
								}
								if(that.Isdistribution == 1){
									if(that.StoreLists[i].StoreID == that.NowSelectGoods.StoreID2){
										that.NowSelectGoods.stockName2 = that.StoreLists[i].StoreName
									}
								}
							}
							console.log('结果')
							console.log(that.NowSelectGoods)
							// console.log(that.NowSelectGoods)
							// that.NowSelectGoods.StoreID = res.data.ResultMsg[0].BranchID;
							// responseData.forEach((item, index) => {
							// 	that.picker2.push(item.StoreName);
							// });
						}
					} else {
			
					}
				});
			},
			indexOfs:function(e){
				var str = "'"+e+"'"
				console.log('是否包含小数')
				console.log(str)
				console.log(str.indexOf(".") != -1)
				return str.indexOf(".") != -1
			},
			//获取当前选择的商品
			addSelectGoods(){
				// if(this.index2==-1 && this.orderType!=10){
				// 	Api.showTip("请选选择仓库");
				// 	return;
				// }
				if(this.NowSelectGoods.Qty ==0 || this.NowSelectGoods.Qty == undefined){
					// Api.showTip("商品数量不能少于一件!");
					uni.showToast({
						title:'商品数量不能少于一件!',
						icon:'none'
					})
					return
				}
				if(this.indexOfs(this.NowSelectGoods.Tax)){
					uni.showToast({
						title:'税率不能包含小数!',
						icon:'none'
					})
					return
				}
				if(this.indexOfs(this.NowSelectGoods.Discount)){
					uni.showToast({
						title:'折扣不能包含小数!',
						icon:'none'
					})
					return
				}
				this.NowSelectGoods.GoodsStorm = this.GoodsStorm;
				this.NowSelectGoods.Tax = parseFloat(this.NowSelectGoods.Tax);
				this.NowSelectGoods.IsGift = this.Gindex
				this.NowSelectGoods.Amount  = this.computPrice(this.NowSelectGoods)
				// this.Gindex = this.Gift[evt].Gid
				// console.log('返回的参数')
                
				
				// console.log(this.NowSelectGoods)
				// return 
				// return
				let data = {};
				data.index = this.index;
				data.NewGoodInfo = JSON.stringify(this.NowSelectGoods);
				var result = this.Isbill(this.NowSelectGoods)
				var that = this
				if(result.Isbills == 0){
					Api.showConfirm("源单明细中没有此商品,是否添加？", function(state) {
						if (state) {
							that.$eventHub.$emit('updateGood', data);
							uni.navigateBack({
								delta:1
							})
						}
					})
				}else if(result.Isgreater== 1){
					Api.showConfirm("录入的数量大于源单数量,是否添加？", function(state,) {
						if (state) {
							that.$eventHub.$emit('updateGood', data);
							uni.navigateBack({
								delta:1
							})
						}
					})
				}else{
					that.$eventHub.$emit('updateGood', data);
					uni.navigateBack({
						delta:1
					})
				}
				
			},
			//判断是否在单据里面  判断商品数量是否大于单据数量
			//判断录入数量是否大于源单数量
			Isbill:function(data){
				var result = {
					Isbills:0,
					Isgreater:0,
				}
				var tmpGoods = this.source
				console.log('数组对比');
				console.log(data);
				console.log(tmpGoods)
				var that = this;
				for(var j in tmpGoods){
					    // data["IsGift"] = data["IsGift"] == "0"?false:true;
						tmpGoods[j]["IsGift"] = tmpGoods[j]["IsGift"] == false || "0"?"0":"1";
						tmpGoods[j]["Qty"] = parseFloat(tmpGoods[j]["Qty"])
					    console.log('-------这是对比HOME---------');
					    console.log('这是商品ID', "选中" + data["GoodsID"], "源单" + tmpGoods[j]["GoodsID"]);
					    console.log('这是商品名称', "选中" + data["GoodsName"], "源单" + tmpGoods[j]["GoodsName"]);
					    console.log('这是单位', "选中" + data["UnitID"], "源单" + tmpGoods[j]["UnitID"]);
					    console.log('这是仓库', "选中" + data["StoreID"], "源单" + tmpGoods[j]["StoreID"]);
					    console.log('这是赠品', "选中" + data["IsGift"], "源单" + tmpGoods[j]["IsGift"]);
					    console.log('这是批号', "选中" + that.isnulls(data["BatchNo"]), "源单" + that.isnulls(tmpGoods[j]["BatchNo"]))
					    console.log('这是单价', "选中" + parseFloat(data["Price"]), "源单" + parseFloat(tmpGoods[j]["Price"]));
					    console.log('这是税率', "选中" + data["Tax"], "源单" + tmpGoods[j]["Tax"]);
					    console.log('这是折扣', "选中" + data["Discount"], "源单" + tmpGoods[j]["Discount"]);
					    console.log('这是生产日期', "选中" + that.isnulls(that.timesubstr(data["validityDate"])), "源单" + that.isnulls(that.timesubstr(tmpGoods[j]["validityDate"])))
					    console.log('这是有效日期', "选中" + that.isnulls(that.timesubstr(data["ProductionDate"])), "源单" + that.isnulls(that.timesubstr(tmpGoods[j]["ProductionDate"])))
						if(tmpGoods[j]["GoodsName"] == data["GoodsName"] 
						   && tmpGoods[j]["GoodsID"] == data["GoodsID"] 
						   && tmpGoods[j]["StoreID"] == data["StoreID"]
						   && tmpGoods[j]["UnitID"] == data["UnitID"]
						   && tmpGoods[j]["IsGift"] == data["IsGift"]
						   // && that.isnulls(tmpGoods[j]["BatchNo"]) == that.isnulls(data["BatchNo"])
						   && parseFloat(tmpGoods[j]["Price"]) == parseFloat(data["Price"])
						   && tmpGoods[j]["Tax"] == data["Tax"]
						   && tmpGoods[j]["Discount"] == data["Discount"]
						   // && that.isnulls(that.timesubstr(tmpGoods[j]["ProductionDate"])) == that.isnulls(that.timesubstr(data["ProductionDate"]))
						   // && that.isnulls(that.timesubstr(tmpGoods[j]["validityDate"])) == that.isnulls(that.timesubstr(data["validityDate"]))
							){
							//console.log('存在');
							
							//console.log(data["Qty"])
							//console.log(parseFloat(this.tmpGoods[i]["Qty"]))
							console.log('是源单商品')
							console.log('输入的数量')
							console.log(parseFloat(data["Qty"]))
							console.log('源单的数量')
							console.log(tmpGoods[j]["Qty"])
							// for()
							
							if(that.batch == 1){
								result.Isbills = 1;
								if(parseFloat(data["Qty"])>parseFloat(tmpGoods[j]["Qty"])){
									result.Isgreater = 1;
								}
							}else{
								if(that.isnulls(tmpGoods[j]["BatchNo"]) == that.isnulls(data["BatchNo"])
								&& that.isnulls(that.timesubstr(tmpGoods[j]["ProductionDate"])) == that.isnulls(that.timesubstr(data["ProductionDate"]))
								&& that.isnulls(that.timesubstr(tmpGoods[j]["validityDate"])) == that.isnulls(that.timesubstr(data["validityDate"]))){
									result.Isbills = 1;
									if(parseFloat(data["Qty"])>parseFloat(tmpGoods[j]["Qty"])){
										result.Isgreater = 1;
									}
								}
							}
						}
				}
				return result
			},
			isnulls:function(e){
				return e == "" || typeof e == 'undefined' ?"":e
			},
			//价格跟踪
			prices:function(e){
				let data = {
					// this.NowSelectGoods
					ClientID :this.NowSelectGoods.ClientID,
					StoreID:this.NowSelectGoods.StoreID,
					BillName: this.Bname,
					GoodsID:this.NowSelectGoods.GoodsID,
					UnitID:this.NowSelectGoods.UnitID,
					URate:this.NowSelectGoods.urate,
					VIPID:''
				}
				var that = this;
				Api.XH_Get_PriceFollowMessage(data, function(res) {
					if (res.state) {
						if (res.data.ErrorMsg == "获取登录信息失败") {
							Api.showTip("登录超时");
						} else if (res.data.ErrorMsg != "") {
							Api.showTip(res.data.ErrorMsg);
						} else {
							that.Pricelist = res.data.ResultMsg
							if(e == 1){
							   that.NowSelectGoods.Price = 	parseFloat(that.Pricelist[0].Price)
							}
							console.log('打印价格跟踪')
							console.log(parseFloat(that.Pricelist[0].Price))
							// that.NowSelectGoods["Price"]=parseFloat(res.data.ResultMsg[0]["Price"])
						    console.log(res.data.ResultMsg[0]["Price"])
						}
					} else {
							Api.showTip("服务器错误!");
					}
				});
			},
			//获取仓库库存
			GetStoreNum:function(){
				let data = {
					StoreID: this.NowSelectGoods.StoreID,
					GoodsID: this.NowSelectGoods.GoodsID,
					BillName: this.Bname
				};
				var _this = this;
				GetApi.Select_StockNum(data, (res) => {
					if (res.data.ErrorMsg == "获取登录信息失败") {
				
					} else if (res.data.ErrorMsg != "") {
						GetApi.showTip(res.data.ErrorMsg);
					} else {
						// _this.GoodsStorm = res.data.ResultMsg;
						_this.NowSelectGoods.stockqty = res.data.ResultMsg;
					}
				});
			},
			// 获取多单位
			getGoodsUnitMessage:function(){
				var that = this;
				let data = {
					GoodsID:this.NowSelectGoods.GoodsID,
				}
				Api.Get_GoodsUnitMessage(data, function(res) {
					if (res.state) {
						if (res.data.ErrorMsg == "获取登录信息失败") {
							Api.showTip("登录超时");
						} else if (res.data.ErrorMsg != "") {
							Api.showTip(res.data.ErrorMsg);
						} else {
							that.GoodsUnit = res.data.ResultMsg;
			
						}
					} else {
							Api.showTip("服务器错误!");
					}
				});
			},
			//计算折扣后商品价格
			computPrice(item){
				// Amount
				
				var Amount = item.Price*item.Qty*(item.Discount/100)*(1+item.Tax/100);
				return Amount;
			},
			timesubstr:function(e){
				return e==""||e==undefined?"":e.substring(0,10)
			},
			GetBatchNo: function(e) {
				console.log('输入的值')
			
				var val = e.detail.value
				console.log(val)
				console.log(this.storeList)
				// this.storeList
				var stutas = false;
				var index = i;
				for (var i in this.storeList) {
					if (this.storeList[i]["FBatchNo"] == val) {
						stutas = true
						index = i
						break
					}
				}
				if (stutas == true) {
					this.ProductionDate = this.timesubstr(this.storeList[index].FDate);
					this.validityDate = this.timesubstr(this.storeList[index].FValidDate);
					this.NowSelectGoods.ProductionDate = this.storeList[index].FDate;
					this.NowSelectGoods.validityDate = this.storeList[index].FValidDate;
					this.NowSelectGoods.BatchNo = this.storeList[index].FBatchNo;
					this.NowSelectGoods.stockqty = parseFloat(this.storeList[index].FQty);
				} else {
					let date = new Date();
					this.BillDate = GetApi.splitdate(date.getFullYear() + "-" + (date.getMonth() + 1) + "-" + date.getDate());
					
					this.ProductionDate = this.BillDate;
					this.validityDate = this.DateToTime(this.BillDate,0,30);
					this.NowSelectGoods.ProductionDate = this.BillDate;
					this.NowSelectGoods.validityDate = this.DateToTime(this.BillDate,0,30);
					this.NowSelectGoods.BatchNo = val;
					this.NowSelectGoods.stockqty = 0;
				}
			},
			// console.log('时间')
			// console.log(date)
			
			// 1.时间,2.(0是加,1是减),3.有效天数
			DateToTime: function(e, count, num) {
				var date = new Date(e);
				var time = Date.parse(date);
				// var dates = Math.round(time / 1000) - 2592000;
				var dates = Math.round(time / 1000);
				// console.log('转换成功')
				var times = null
				if (count == 0) {
					times = (dates + (60 * 60 * 24 * (Number(num))))
				} else if (count == 1) {
					times = (dates - (60 * 60 * 24 * (Number(num))))
				}
				var datess = new Date(Math.round(times * 1000));
				var YY = datess.getFullYear() + '-';
				var MM = (datess.getMonth() + 1 < 10 ? '0' + (datess.getMonth() + 1) : datess.getMonth() + 1) + '-';
				var DD = datess.getDate() + '';
				console.log('调用了时间戳转日期')
				console.log(YY + MM + DD)
				var res = GetApi.splitdate(YY + MM + DD)
				return res
			},
		}
	}
</script>

<style>
	/* @import url("./goodlist.css"); */
	/* 弹出框样式 */
		.cu-dialog{
			height: 70%;
		}
		.new-cu-dialog{
			height: 34%;
		}
		.btn_list{
			width: 100%;
			height: 40px;
			background-color: #07C160;
			color: #fff;
			text-align: center;
			line-height: 40px;
			border-radius: 5px;
			box-shadow: 0 2px 8px rgba(211, 209, 209, 0.75);
			/* margin: 7px 0; */
			margin-top: 15px;
			font-size: 16px;
		}
		.search{ 
			width: 100%;
			height: 40px;
			margin: 0 10px 0 0;
			/* background-color: #00B7B8; */
			border-radius: 5px;
			border: 1px solid #bcbbbb;
			/* padding: 21px; */
			
		}
	    .search_span{
		width: 20%;
		height: 37px;
		background-color: #659AFF;
		color: #FFFFFF;
		text-align: center;
		display: inline-block;
		line-height: 37px;
		float: right;
		border-radius: 5px;
		/* margin: 1px; */
	    }
		/* .search::before{
			content: '搜索'; */
		
			/* border-bottom-right-radius: 5px;
			border-top-right-radius: 5px; */
		/* } */
		.search>input{
			line-height: 40px;
			float: left;
			text-align: left;
			margin-left:5px ;
			margin-top: 6px;
		}
		.content{
			font-size: 16px;
		}
		.padding-xl{
			overflow-y: scroll;
			padding: 5px 20px;
		}
		.newbtn_list{
			margin: 0;
			margin-bottom: 15px;
		}
		.cu-form-group>input{
			font-size: 28upx;
		}
		.save{
			width: 100%;
			height: 40px;
			background-color: #007AFF;
			color: #fff;
			position: fixed;
			bottom: 0;
			left: 0;
			text-align: center;
			font-size: 18px;
			line-height: 40px;
		}
		.setfixeds{
			width: 23%;
			margin: 4px;
		}
		.padd_left{
			padding-left: 12px;
		}
		.ls-box{
			width: 100%;
			height: 40px;
			border-radius: 5px;
			margin: 10px 0;
			line-height: 40px;
			font-size: 18px;
			text-align: center;
			color: #fff;
			background-color: #43a047;
			box-shadow: 0 7px 14px 0 rgba(59, 65, 94, 0.1), 0 3px 6px 0 rgba(0, 0, 0, 0.07);
		}
</style>